package com.ce.pms.custservice.web;

import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.custservice.service.ICustServChargeService;
import com.ce.pms.custservice.service.IDFormManageService;
import com.ce.pms.custservice.vo.BillVO;
import com.ce.util.BlankUtil;
import com.sitechasia.webx.core.annotation.Out;
import com.sitechasia.webx.core.annotation.Read;

public class CustServiceChargeAction extends PmsBaseAction {

	/**
	 * 功能描述:导航到费用核算主页面<br>
	 * @param <br>
	 * @return<br>
	 *
	 * Create author:xuhaidui<br>
	 * Create on:2008-12-18<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public String navigateChargeCalculateMain(@Read(key="dispatchFormId")@Out(key="dispatchFormId")Long dispatchFormId){
		BillVO VO=custServChargeService.getBillVOByDispatchFormId(dispatchFormId);
		this.getRequest().setAttribute("billVO", VO);
		return "chargeCalculateMain";
	}

	/**
	 * 功能描述:导航到费用核算项目列表页面<br>
	 * @param <br>
	 * @return<br>
	 *
	 * Create author:xuhaidui<br>
	 * Create on:2008-12-18<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	@Deprecated
	public String navigateChargeCalculateItemList(@Read(key="dispatchFormId")@Out(key="dispatchFormId")Long dispatchFormId){
		return "chargeItemCompoundList";
	}

	/**
	 * 功能描述:保存账单<br>
	 * @param <br>
	 * @return<br>
	 *
	 * Create author:xuhaidui<br>
	 * Create on:2008-12-18<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public String editBill(@Read BillVO billVO){
		billVO.setModifier(this.getUserId());
		billVO=custServChargeService.editBill(billVO);
		this.renderText(billVO.getKeyword().toString());
		return null;
	}

	/**
	 * 功能描述:保存账单<br>
	 * @param <br>
	 * @return<br>
	 *
	 * Create author:xuhaidui<br>
	 * Create on:2008-12-18<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public String saveBill(@Read BillVO billVO){
		 dispatchFormManageService.checkIsAllowAddBill(billVO.getDispatchFormId());
		  billVO.setCreator(this.getUserId());
		  billVO=custServChargeService.addBill(billVO.getDispatchFormId(), billVO);
		  this.renderText(billVO.getKeyword().toString());
		return null;
	}

	public String deliveryCharge(@Read BillVO billVO){

		BillVO VO=custServChargeService.getBillVOByDispatchFormId(billVO.getDispatchFormId());

		//当还没有保存账单，要先保存，然后才进行费用传递
		if(BlankUtil.isBlank(VO.getKeyword())){
			billVO.setCreator(this.getUserId());
			billVO=custServChargeService.addBill(billVO.getDispatchFormId(), billVO);
		}
		custServChargeService.delivery(billVO.getKeyword(), this.getUserId());

		this.renderText("true");
		return null;
	}

	private ICustServChargeService custServChargeService;

	private IDFormManageService dispatchFormManageService;

	public void setCustServChargeService(
			ICustServChargeService custServChargeService) {
		this.custServChargeService = custServChargeService;
	}

	public void setDispatchFormManageService(IDFormManageService dispatchFormManageService) {
		this.dispatchFormManageService = dispatchFormManageService;
	}

}
